/*
 *  db.h
 *  
 *
 *  Created by Zhenjie Zhang on 12/20/11.
 *  Copyright 2011 Thothe. All rights reserved.
 *
 */

#ifndef _DB_H_
#define _DB_H_

#include "contest_interface.h"
#include "access/BufferManager.h"
#include "storage/DatumPage.h"
#include "access/Transaction.h"

#include <set>

#define MAX_INDEX_NAME_LEN 128

using namespace std;

class Database {
public:
	
	Database(const char* name, uint8_t column_count, KeyType type, BufferManager* man);
	
	~Database();

    Database(const Database &d);

	void ReportInfo();

    bool InsertRecord(Record* rec, Transaction* trans);
    
    static void CopyDatabase(Database* dest, Database* source);

    pthread_mutex_t* LockPage();
 
private:

	// database basic information
	char			index_name[MAX_INDEX_NAME_LEN];
	AttributeType	*index_type;
	//void*			buffer;
	int32_t			index_size;
	int32_t			unit_size;
	uint8_t			dim;

    pthread_mutex_t db_mutex;
	
	// storage information
	BufferManager* bm;

    DatumPage* headPage; 
    
	// functions
};

#endif
